<?php
Junction_FileCabinet::using("Junction_Core_Iterator");
Junction_FileCabinet::using("Junction_Core_Mapping");
Junction_FileCabinet::using("Test_Mock_Client");

class Test_Junction_Core_Iterator extends UnitTestCase {
	
	private $_dsn = "mysql://Catch22:divein@localhost/JunctionTest";
	
	private $_mapping;
	
	private $_results;

	public function testBuild() {
		$this->_mapping = new Junction_Core_Mapping("Test_Mock_Client", "users");
		$this->_mapping->bindKey(new Junction_Core_Property("Id", "id"));
		$this->_mapping->bindProperty(new Junction_Core_Property("Email", "email"));
		$this->_mapping->bindProperty(new Junction_Core_Property("Date", "date_added"));
		$this->_mapping->bindProperty(new Junction_Core_Property("Password", "password"));
		
		$dbh = new Junction_Db_Adodb_Service($this->_dsn);
		$query = "SELECT * FROM users";
		$this->_results = $dbh->select($query);
		
		$iterator = new Junction_Core_Iterator($this->_results, $this->_mapping);
	}
	
	public function testCurrent() {
		$iterator = new Junction_Core_Iterator($this->_results, $this->_mapping);
		$client = $iterator->current();
		$this->assertTrue(is_a($client, "Test_Mock_Client"));
	}
	
	public function testIterate() {
		$iterator = new Junction_Core_Iterator($this->_results, $this->_mapping);
		foreach ($iterator as $client) {
			$i++;
		}
		$this->assertTrue($i > 0);
	}
}
?>